package com.cxrj.zhsq.autonomy.controller;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.cxrj.zhsq.autonomy.entity.AutonomyCommittee;
import com.cxrj.zhsq.autonomy.entity.AutonomyCommitteeOrderWithBLOBs;
import com.cxrj.zhsq.autonomy.entity.AutonomyForward;
import com.cxrj.zhsq.autonomy.entity.AutonomyGroup;
import com.cxrj.zhsq.autonomy.entity.AutonomySecretary;
import com.cxrj.zhsq.autonomy.service.AutonomyService;

@RestController
public class AutonomyController {

	@Resource
	private AutonomyService autonomyService;

	/**
	 * 分页查询日志
	 * 
	 * @return
	 */
	@RequestMapping(value = "selectSecretarys", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	@ResponseBody
	public Map<String, Object> selectSecretarys(HttpServletRequest request, HttpServletResponse response) {
		return autonomyService.selectSecretaryPager(request, response);
	}

	/**
	 * 根据id查询
	 * 
	 * @return
	 */
	@RequestMapping(value = "selectSecretaryById", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> selectSecretaryById(String id, HttpServletRequest request) {
		return autonomyService.selectSecretaryById(id, request);
	}

	/**
	 * 修改信息
	 * 
	 * @return
	 */
	@RequestMapping(value = "updateSecretary", method = RequestMethod.POST)
	public Map<String, Object> updateSecretary(AutonomySecretary autonomySecretary, HttpServletRequest request) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {
			autonomySecretary.setAuditTime(new Date());
			autonomySecretary.setOperatorAccount(request.getSession().getAttribute("userAccount").toString());
			resultMap = autonomyService.updateSecretary(autonomySecretary);
		} catch (Exception e) {
			resultMap.put("result", 0);
			e.printStackTrace();
		}
		return resultMap;
	}

	/**
	 * 修改信息
	 * 
	 * @return
	 */
	@RequestMapping(value = "feedbackSecretary", method = RequestMethod.POST)
	public Map<String, Object> feedbackSecretary(AutonomySecretary autonomySecretary, HttpServletRequest request) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {
			autonomySecretary.setFeedbackTime(new Date());
			autonomySecretary.setOperatorAccount(request.getSession().getAttribute("userAccount").toString());
			resultMap = autonomyService.updateSecretary(autonomySecretary);
		} catch (Exception e) {
			resultMap.put("result", 0);
			e.printStackTrace();
		}
		return resultMap;
	}

	/**
	 * 分页查询日志
	 * 
	 * @return
	 */
	@RequestMapping(value = "selectCommittees", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	@ResponseBody
	public Map<String, Object> selectCommittees(HttpServletRequest request, HttpServletResponse response) {
		return autonomyService.selectCommitteePager(request, response);
	}

	/**
	 * 根据id查询
	 * 
	 * @return
	 */
	@RequestMapping(value = "selectCommitteesById", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> selectCommitteesById(String id, HttpServletRequest request) {
		return autonomyService.selectCommitteeById(id, request);
	}

	/**
	 * 添加居委会
	 * 
	 * @return
	 */
	@RequestMapping(value = "insertAndUpdateCommittee", method = RequestMethod.POST)
	public Map<String, Object> insertAndUpdateCommittee(AutonomyCommittee autonomyCommittee, HttpServletRequest request) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {
			resultMap = autonomyService.insertAndUpdateCommittee(autonomyCommittee);
		} catch (Exception e) {
			resultMap.put("result", 0);
			e.printStackTrace();
		}
		return resultMap;
	}
	
	/**
	 * 修改居委会
	 * 
	 * @return
	 */
	@RequestMapping(value = "updateCommittee", method = RequestMethod.POST)
	public Map<String, Object> updateCommittee(AutonomyCommittee autonomyCommittee, HttpServletRequest request) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {
			resultMap = autonomyService.updateCommittee(autonomyCommittee);
		} catch (Exception e) {
			resultMap.put("result", 0);
			e.printStackTrace();
		}
		return resultMap;
	}

	/**
	 * 查询预约信息
	 * 
	 * @return
	 */
	@RequestMapping(value = "selectCommitteeOrders", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	@ResponseBody
	public Map<String, Object> selectCommitteeOrders(HttpServletRequest request, HttpServletResponse response) {
		return autonomyService.selectCommitteeOrderPager(request, response);
	}

	/**
	 * 根据id查询
	 * 
	 * @return
	 */
	@RequestMapping(value = "selectCommitteeOrderById", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> selectCommitteeOrderById(String id, HttpServletRequest request) {
		return autonomyService.selectCommitteeOrderById(id, request);
	}

	/**
	 * 修改信息
	 * 
	 * @return
	 */
	@RequestMapping(value = "updateCommitteeOrder", method = RequestMethod.POST)
	public Map<String, Object> updateCommitteeOrder(AutonomyCommitteeOrderWithBLOBs autonomyCommitteeOrder, HttpServletRequest request) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {
			autonomyCommitteeOrder.setAuditTime(new Date());
			autonomyCommitteeOrder.setS3(request.getSession().getAttribute("userAccount").toString());
			resultMap = autonomyService.updateCommitteeOrder(autonomyCommitteeOrder);
		} catch (Exception e) {
			resultMap.put("result", 0);
			e.printStackTrace();
		}
		return resultMap;
	}

	/**
	 * 分页一键提报
	 * 
	 * @return
	 */
	@RequestMapping(value = "selectForwards", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	@ResponseBody
	public Map<String, Object> selectForwards(HttpServletRequest request, HttpServletResponse response) {
		return autonomyService.selectForwardPager(request, response);
	}

	/**
	 * 根据id查询一键提报
	 * 
	 * @return
	 */
	@RequestMapping(value = "selectForwardById", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> selectForwardById(String id, HttpServletRequest request) {
		return autonomyService.selectForwardById(id, request);
	}

	/**
	 * 修改一键提报
	 * 
	 * @return
	 */
	@RequestMapping(value = "updateForward", method = RequestMethod.POST)
	public Map<String, Object> updateForward(AutonomyForward autonomyForward, HttpServletRequest request) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {
			autonomyForward.setS1(request.getSession().getAttribute("userAccount").toString());
			resultMap = autonomyService.updateForward(autonomyForward);
		} catch (Exception e) {
			resultMap.put("result", 0);
			e.printStackTrace();
		}
		return resultMap;
	}

	/**
	 * 分页找群团
	 * 
	 * @return
	 */
	@RequestMapping(value = "selectGroups", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	@ResponseBody
	public Map<String, Object> selectGroups(HttpServletRequest request, HttpServletResponse response) {
		return autonomyService.selectGroupPager(request, response);
	}

	/**
	 * 根据id查询找群团
	 * 
	 * @return
	 */
	@RequestMapping(value = "selectGroupById", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> selectGroupById(String id, HttpServletRequest request) {
		return autonomyService.selectGroupById(id, request);
	}

	/**
	 * 添加找群团
	 * 
	 * @return
	 */
	@RequestMapping(value = "insertAndUpdateGroup", method = RequestMethod.POST)
	public Map<String, Object> insertAndUpdateGroup(AutonomyGroup autonomyGroup, HttpServletRequest request) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {
			resultMap = autonomyService.insertAndUpdateGroup(autonomyGroup);
		} catch (Exception e) {
			resultMap.put("result", 0);
			e.printStackTrace();
		}
		return resultMap;
	}
}
